06. Comments
Comments
Comments
Let's take a quick diversion to cover something useful: code comments.
A comment is a human-readable message inside code. Comments are usually surrounded by or preceded by special characters that instruct computers to completely ignore whatever text is inside the comment. Comments are great because they allow you, the developer, to leave clarifying messages and instructions for other developers (as well as your future self!). Every programming language gives you the ability to write comments.
Comments are also useful when you're testing your code. Rather than deleting potentially useful chunks of code, you can comment them out, getting the same effect without the risk of accidentally losing work!
CSS Comments
You saw a CSS comment in the code from your previous quiz:
p {
color: blue;
}
/* add CSS here */
h1 {
color: red;
}
The line /* add CSS here */
is a comment. CSS comments are surrounded by an opening /*
and a closing */
. You must use both. The comment made it clear to you where you needed to add your code and it did not affect the style of the page in any way.
HTML Comments
You can write comments in HTML too! Here's how they look.
<!-- This is a comment -->
<div class="example">Words, words, words.</div>
You must surround your HTML comments with a starting <!--
and a closing -->
.
Now, back to CSS.